package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Insert();
        Select();
    }
    public void Insert(){
        DbHelper db = new DbHelper(this);
        SQLiteDatabase writ = db.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("name", "zhangsan");
        values.put("age", 18);
        values.put("sex", "男");
        writ.insert("student", null, values);
        ContentValues value = new ContentValues();
        value.put("name", "lisi");
        value.put("age", 19);
        value.put("sex", "男");
        writ.insert("student", null, value);
        writ.close();
    }
    public void Delete(){
        DbHelper db = new DbHelper(this);
        SQLiteDatabase writ = db.getWritableDatabase();
        writ.delete("student", "name = ?", new String[]{"zhangsan"});
        writ.close();
    }
    public void Select(){
        DbHelper db = new DbHelper(this);
        SQLiteDatabase writ = db.getWritableDatabase();
        Cursor c = writ.query("student", null, null, null, null, null, null);
        while (c.moveToNext()){
            System.out.println(c.getString(0)+"");
            System.out.println(c.getString(1)+"");
            System.out.println(c.getInt(2)+"");
            System.out.println(c.getString(3)+"");
        }

    }
}